package com.ztorn.fiscale.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ztorn.common.core.utils.poi.ExcelUtil;
import com.ztorn.common.core.web.controller.BaseController;
import com.ztorn.common.core.web.domain.AjaxResult;
import com.ztorn.common.core.web.page.TableDataInfo;
import com.ztorn.common.log.annotation.Log;
import com.ztorn.common.log.enums.BusinessType;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ztorn.fiscale.domain.FiscaleDocumentType;
import com.ztorn.fiscale.service.IFiscaleDocumentTypeService;

/**
 * 单证类型Controller
 *
 * @author ztorn
 */
@RestController
@RequestMapping("/documentType")
public class FiscaleDocumentTypeController extends BaseController
{
    @Autowired
    private IFiscaleDocumentTypeService fiscaleDocumentTypeService;

    /**
     * 查询单证类型列表
     */
    @PreAuthorize("@ss.hasPermi('fiscale:documentType:list')")
    @GetMapping("/list")
    public TableDataInfo list(FiscaleDocumentType fiscaleDocumentType)
    {
        startPage();
        List<FiscaleDocumentType> list = fiscaleDocumentTypeService.selectFiscaleDocumentTypeList(fiscaleDocumentType);
        return getDataTable(list);
    }

    /**
     * 导出单证类型列表
     */
    @PreAuthorize("@ss.hasPermi('fiscale:documentType:export')")
    @Log(title = "单证类型", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public void export(HttpServletResponse response, FiscaleDocumentType fiscaleDocumentType)
    {
        List<FiscaleDocumentType> list = fiscaleDocumentTypeService.selectFiscaleDocumentTypeList(fiscaleDocumentType);
        ExcelUtil<FiscaleDocumentType> util = new ExcelUtil<FiscaleDocumentType>(FiscaleDocumentType.class);
        util.exportExcel(response, list, "单证类型数据");
    }

    /**
     * 获取单证类型详细信息
     */
    @PreAuthorize("@ss.hasPermi('fiscale:documentType:query')")
    @GetMapping(value = "/{typeId}")
    public AjaxResult getInfo(@PathVariable("typeId") Long typeId)
    {
        return AjaxResult.success(fiscaleDocumentTypeService.selectFiscaleDocumentTypeById(typeId));
    }

    /**
     * 新增单证类型
     */
    @PreAuthorize("@ss.hasPermi('fiscale:documentType:add')")
    @Log(title = "单证类型", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody FiscaleDocumentType fiscaleDocumentType)
    {
        return toAjax(fiscaleDocumentTypeService.insertFiscaleDocumentType(fiscaleDocumentType));
    }

    /**
     * 修改单证类型
     */
    @PreAuthorize("@ss.hasPermi('fiscale:documentType:edit')")
    @Log(title = "单证类型", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody FiscaleDocumentType fiscaleDocumentType)
    {
        return toAjax(fiscaleDocumentTypeService.updateFiscaleDocumentType(fiscaleDocumentType));
    }

    /**
     * 删除单证类型
     */
    @PreAuthorize("@ss.hasPermi('fiscale:documentType:remove')")
    @Log(title = "单证类型", businessType = BusinessType.DELETE)
	@DeleteMapping("/{typeIds}")
    public AjaxResult remove(@PathVariable Long[] typeIds)
    {
        return toAjax(fiscaleDocumentTypeService.deleteFiscaleDocumentTypeByIds(typeIds));
    }
}
